package com.family.gmall.product.controller;

import com.family.gmall.common.result.Result;
import com.family.gmall.model.product.entity.BaseAttrInfo;
import com.family.gmall.model.product.entity.BaseAttrValue;
import com.family.gmall.product.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: family
 * @Date: 2023/7/10 10:00
 * @Description:
 */
@Api(tags = "商品基础属性接口")
@RestController
@RequestMapping("/admin/product")
public class BaseManageController {
    @Resource
    private ManageService manageService;

    @ApiOperation("获取一级分类")
    @GetMapping("/getCategory1")
    public Result getCategory1() {
        return Result.ok(manageService.getCategory1());
    }

    @ApiOperation("获取二级分类")
    @ApiImplicitParam(name = "一级分类id", value = "categoryId", required = true)
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id) {
        return Result.ok(manageService.getCategory2(category1Id));
    }

    @ApiOperation("获取三级分类")
    @ApiImplicitParam(name = "二级分类id", value = "category2Id", required = true)
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id) {
        return Result.ok(manageService.getCategory3(category2Id));
    }

    @ApiOperation("根据分类id获取平台属性")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "一级分类id", value = "category1Id", required = true),
            @ApiImplicitParam(name = "二级分类id", value = "category2Id", required = true),
            @ApiImplicitParam(name = "三级分类id", value = "category3Id", required = true)}
    )
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(
            @PathVariable Long category1Id,
            @PathVariable Long category2Id,
            @PathVariable Long category3Id) {
        return Result.ok(manageService.getAttrInfoList(category1Id, category2Id, category3Id));
    }

    @ApiOperation("保存、修改平台属性方法")
    @ApiImplicitParam(name = "属性对象", value = "baseAttrInfo", required = true)
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok().message("保存成功");
    }

    @ApiOperation("根据平台属性ID获取平台属性对象数据")
    @ApiImplicitParam(name = "平台属性Id", value = "attrId", required = true)
    @GetMapping("/getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable Long attrId) {
        return Result.ok(manageService.getAttrInfo(attrId).getAttrValueList());
    }
}
